var $;
var letterId;
layui.config({
    base : "../../js/"
}).use(['form','layer','layedit'],function() {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        layedit = layui.layedit;
    $ = layui.jquery;

    //消息回复
    var editIndex = layedit.build('msgReply', {
        tool: ['face'],
        height: 100
    });

    //提交回复
    $(".send_msg").click(function(){
        var content = layedit.getContent(editIndex);
        var userId = userId1;
        var letterId = letterId1;
        if(content != ''){
            $.ajax({
                url:"insertLetterReply",
                type:"get",
                data:{
                    "userId":userId,
                    "content":content,
                    "letterId":letterId
                },
                success:function (result) {
                    if (result.code == 100){
                        layer.msg("回复成功",{offset:'300px'});
                    } else {
                        layer.msg("回复失败",{offset:'300px'});
                    }
                }
            })
            var replyHtml = '';
            replyHtml += '<tr>';
            replyHtml += '  <td class="msg_info">';
            replyHtml += '    <img src="../../images/face.jpg" width="50" height="50">';
            replyHtml += '    <div class="user_info">';
            replyHtml += '        <h2>请叫我马哥</h2>';
            replyHtml += '        <p>'+layedit.getContent(editIndex)+'</p>';
            replyHtml += '    </div>';
            replyHtml += '  </td>';
            replyHtml += '  <td class="msg_time">'+formatTime(new Date())+'</td>';
            replyHtml += '  <td class="msg_reply"></td>';
            replyHtml += '</tr>';
            $(".msgReplyHtml").prepend(replyHtml);
            $("#LAY_layedit_1").contents().find("body").html('');
        }else{
            layer.msg("请输入回复信息",{offset:'300px'});
        }
    })
})
